<?php
namespace app\admin\controller;
use think\Db;
class Tuiali extends Base {
// 定义配置项
    protected $config = array(
        'app_id' => '202108',
        'ali_public' => 'KddQIDAQAB',
        'public_key' => 'MIAQAB',
        'private_key' => 'MII43X8'
    );
    //----------------------------提现 S-----------------------------------
    /**
     *支付宝的原路退款接口(商户处理用户的订单)
     */
    public function refund($payInfo,$refundNo){
        //仨参数：money,number
        import('alipay.aop.AopClient',EXTEND_PATH);
        import('alipay.aop.request.AlipayTradeRefundRequest',EXTEND_PATH);
        $aop = new \AopClient;
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = $this->config['app_id'];
        $aop->rsaPrivateKey = $this->config['private_key'];
        $aop->alipayrsaPublicKey=$this->config['ali_public'];
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='UTF-8';
        $aop->format='json';
        $request = new \AlipayTradeRefundRequest;
        $refundAmount = $payInfo['money'];
        $request->setBizContent("{" .
            "\"out_trade_no\":\"{$payInfo['number']}\"," .
            "\"refund_amount\":$refundAmount," .
            "\"refund_reason\":\"正常退款\"," .
            "\"out_request_no\":\"$refundNo\"," .
            "\"operator_id\":\"OP001\"," .
            "\"store_id\":\"NJ_S_001\"," .
            "\"terminal_id\":\"NJ_T_001\"" .
            "  }");
        $result = $aop->execute($request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $resultCode = $result->$responseNode->code;
        if(!empty($resultCode) && $resultCode == 10000){
            return array('status'=>200,'msg'=>'操作成功');
        }else{
            return array('status'=>0,'msg'=>'调用接口失败（余额不足或者超出实际支付金额）');
        }
    }


}